var app = getApp();
Page({
    data:{
        order : {},
        sets : null,
        options : null,
        showpayqr : false,
        isIPX : app.globalData.isIPX ? 1 : 0,
        isjifen : false,
        jfactions : [
            {name:'充值积分',url:'/zofui_sales/admin/jifenadd'},
            {name:'赠送积分',url:'/zofui_sales/admin/jifengive'},
            {name:'积分记录',url:'/zofui_sales/admin/jifenlog'}
        ],
        payactions : [
            {name:'收款页面',type:1},
            {name:'收款二维码',type:2}
        ],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        
        app.com.auth(function(user){
            app.com.http('admin','POST',{op:'index'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        shop : res.data.data.shop,
                        shopdata : res.data.data.shopdata,
                        params : res.data.data.params,
                        auth : res.data.data.auth,
                        bindurl : res.data.data.bindurl,
                        isadmin : res.data.data.isadmin,
						'jfactions[0].name' : '充值'+res.data.data.params.jfbname,
						'jfactions[1].name' : '赠送'+res.data.data.params.jfbname,
						'jfactions[2].name' : res.data.data.params.jfbname+'记录',
                    },function(){
                        self.setData({
                            inited : true,
                        });
                    });
                    wx.setNavigationBarTitle({
                      title: res.data.data.shop.name,
                    });
                }else if( res.data.errno == 2 ){
                    wx.setStorageSync('adminshopid','');
                    app.com.alert(res.data.message,function(){
                        wx.navigateTo({
                            url : res.data.data.url
                        })
                    });
                }else{
                    app.com.alert( res.data.message );
                }
            });
        },self);
        wx.setNavigationBarTitle({
          title: '商户主页',
        });
        
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: '商户主页',
            path: '',
        }
    },
    onPullDownRefresh: function () {
        this.onLoad();
        // 关闭下拉刷新
        wx.stopPullDownRefresh();
    },
    toaddress(){
        wx.chooseAddress({
            success: function (res) {}
        })
    },
    loginout(){
        app.com.http('admin','POST',{op:'loginout'},0,true,'','',function(res){
            if (res.data && !res.data.errno) {
                app.com.toast('已退出','success',function(){
                    wx.setStorageSync('adminshopid','');
                    wx.navigateTo({
                        url : res.data.data.url
                    })
                });
            }else{
                app.com.toast( res.data.message );
            }
        });
    },
    qrcode(e){
        var postdata = {
            op:'shopqrcode',
            type : e.currentTarget.dataset.type
        }
        app.com.http('admin','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno) {
                wx.previewImage({
                  current: res.data.data.url,
                  urls: [res.data.data.url]
                })
            }else{
                app.com.alert(res.data.message,function(){
                    if( res.data.errno == 2 ){
                    wx.navigateTo({
                        url : res.data.data.url
                    })
                    }
                });
            }
        });
    },
    toggleDialog(){
        this.setData({
            showpayqr : !this.data.showpayqr,
        })
    },
    showpayqrfn(e){
        if(e.detail.type == 1){
            e.currentTarget.dataset.url = '/zofui_sales/admin/pay?shopid='+this.data.shop.id;
            this.navigateto(e);
        }else if(e.detail.type == 2){
            e.currentTarget.dataset.type = 'pay';
            this.qrcode(e);
        }
    },
    showaction(){
        this.setData({
            isjifen : !this.data.isjifen,
        })
    },
    onSelectjf(e){
        wx.navigateTo({
            url : e.detail.url
        })
    },
    alertinfo(){
        this.setData({
            show : !this.data.show
        })
    },
    copy(){
        var self = this;
        wx.setClipboardData({
            data : self.data.params.loginurl,
            success : function(){}
        });
    },
    toweburl : function(e){
        app.com.toweburl( e,this );
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
})